/*
 * Copyright 2010 Gal Dolber.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.unnison.framework.client.place;

import com.google.inject.Inject;

import com.unnison.framework.client.eventbus.EventBus;
import com.unnison.framework.client.place.event.PlaceBackEvent;
import com.unnison.framework.client.place.event.PlaceDefaultEvent;
import com.unnison.framework.client.place.event.PlaceFowardEvent;
import com.unnison.framework.client.place.event.PlaceGoEvent;
import com.unnison.framework.client.place.event.PlaceNewItemEvent;

public abstract class PlaceManagerBase implements PlaceManager {

    private EventBus eventBus;

    @Override
    public <D> void go(Class<? extends Place<D>> placeClass) {
        eventBus.fireEvent(new PlaceGoEvent(placeClass, null));
    }

    @Override
    public <D> void go(Class<? extends Place<D>> placeClass, D placeData) {
        eventBus.fireEvent(new PlaceGoEvent(placeClass, placeData));
    }

    @Override
    public void go(String token) {
        eventBus.fireEvent(new PlaceGoEvent(token));
    }

    @Override
    public void goBack() {
        eventBus.fireEvent(new PlaceBackEvent());
    }

    @Override
    public void goForward() {
        eventBus.fireEvent(new PlaceFowardEvent());
    }

    @Override
    public void goDefault() {
        eventBus.fireEvent(new PlaceDefaultEvent());
    }

    @Inject
    public void injectEventBus(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    @Override
    public <D> void newItem(Class<? extends Place<D>> placeClass) {
        eventBus.fireEvent(new PlaceNewItemEvent(placeClass, null));
    }

    @Override
    public <D> void newItem(Class<? extends Place<D>> placeClass, D placeData) {
        eventBus.fireEvent(new PlaceNewItemEvent(placeClass, placeData));
    }

    @Override
    public void newItem(String token) {
        eventBus.fireEvent(new PlaceNewItemEvent(token));
    }
}
